﻿


using HBase;
using hCommand;
using Net.http;
using System;
using System.Collections.Generic; 

namespace Persistence
{
    public class PkCase:AbsJjlOutCase {
        public long pkId;
        public WhDopk pk;
        override protected String getWaveNO(long stockId) {
            return "pk"+pkId;
        }

        override protected String createCoreTaskInfo(CoreTask task, int src, int des) {
            return "盘库:" + pk.title+"条码:"+ task.boxCode+"位置:"+ src;
        }
        protected override TransRes perTask() {
            pk =getById<WhDopk>(pkId);
            String detSql = @"update  core_stock s  join core_stock_det d  on s.id=d.pId  join Wh_Dopk_det  p on d.item_Id=p.item_Id  
                    set s.pk_id=p.pid   where  d.status={0} and s.status in ({1},{2}) and p.pid=@id";

            exec(HUtil.s(detSql, StockDetailStatus.库存, StockStatus.库存, StockStatus.库外), pk);
            //小于10000为平库
            String sql = HUtil.s("SELECT * FROM Core_stock  where status ={0}  and pk_id=@pkId", StockStatus.库存);
            List<CoreStock> csLIst = query<CoreStock>(sql, new { pkId });

            foreach (CoreStock cs in csLIst) {
                if (!BUtil.eq(cs.status, StockStatus.库存, StockStatus.库外)) {
                    throw new Exception(cs.boxCode + "状态异常" + cs.status);
                }
                long csId = cs.id;
                addStock(csId);
            } 
            return new TransRes();
        }

       
       
        protected override void after(  ) {
            
            pk.status = 2;
            update(pk, x => x.status );
        }

        
    }
}
